/*
 * Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.example.ventilation.code.fragment.DeviceGroup.Detail;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;

import com.example.ventilation.R;
import com.example.ventilation.base.BaseFragment;
import com.example.ventilation.code.common.model.WindInfoEntity;
import com.example.ventilation.code.fragment.DeviceGroup.Detail.Adapter.MyViewpager2Adapter;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;
import com.xuexiang.xpage.annotation.Page;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import butterknife.BindView;

import static com.google.android.material.tabs.TabLayout.MODE_SCROLLABLE;

/**
 * Detail_DeviceWindFragment
 * 设备监测 - 测风装置 - item - 功能分类汇总
 *
 * @author gehj
 * @time 1/29/21 10:19 AM
 */
@Page(name = "测风装置_详细功能")
public class Detail_Tabs_WindFragment extends BaseFragment {
    @BindView(R.id.tabLayout)
    TabLayout mTabLayout;

    @BindView(R.id.devicewind_viewpage2)
    ViewPager2 mDevicewindViewpage2;

    public static final String[] tabTitles =
            new String[]{"装置信息","实时监控","操作","历史数据查询","风速历史曲线","风量历史曲线",
                    "示意图","编辑信息"};
    private List<Fragment> mFragments = new ArrayList<Fragment>();//fragment集合
    private  WindInfoEntity.WindEntity itemInfo;
    private List<String> tablist = new ArrayList<>();
    private MyViewpager2Adapter viewpager2Adapter; //viewpager2的适配器
    private TabLayoutMediator mediator;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_detail__device_wind;
    }


    @Override
    protected void initViews() {
        initData();



        //禁用预加载
        mDevicewindViewpage2.setOffscreenPageLimit(ViewPager2.OFFSCREEN_PAGE_LIMIT_DEFAULT);
        mDevicewindViewpage2.setAdapter(viewpager2Adapter);
        mTabLayout.setTabMode(MODE_SCROLLABLE);

        //指示器与页面联系 不能在setAdapter之前，否则会报错
        mediator = new TabLayoutMediator(mTabLayout, mDevicewindViewpage2,
                new TabLayoutMediator.TabConfigurationStrategy() {
                    @Override
                    public void onConfigureTab(@NonNull TabLayout.Tab tab,
                                               int position) {
                        tab.setText(tabTitles[position]);
                    }

                });
        mediator.attach(); //fragment与tabview进行连接
    }

    private void initData() {
        Bundle bundle = getArguments();
        //这里就拿到了之前传递的参数
        itemInfo = (WindInfoEntity.WindEntity) bundle.getSerializable("object");
        tablist = Arrays.asList(tabTitles);
        viewpager2Adapter = new MyViewpager2Adapter(getActivity(),mFragments);

        //添加集合
        for(int i = 0; i < tabTitles.length; i++) {
            mFragments.add(BlankFragment.newInstance(tabTitles[i],null));
        }






    }


}